<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DentalGUIHelper;assembly=DentalConfig"
    xmlns:dentalConverters="clr-namespace:DentalConfig.Converters;assembly=DentalConfig">
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary Source="MaterialDesignTheme.NamedTextBlock.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <dentalConverters:BrushToTransmittantBrushConverter x:Key="BrushToTransmittantBrushConverter"/>

    <Style x:Key="ColoredContentAndTextButtonStyle"  TargetType="{x:Type local:ContentAndTextButton}">
        <Style.Resources>
          <Style x:Key="{x:Type TextBlock}" BasedOn="{StaticResource ControlContentTextblock}" TargetType="{x:Type TextBlock}"/>
        </Style.Resources>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Background" Value="{DynamicResource ColoredContentAndTextButtonBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource ColoredContentAndTextButtonForeground}" />
        <Setter Property="BorderThickness" Value="{DynamicResource ColoredContentAndTextButtonBorderThickness}" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="TextDock" Value="Right" />
        <Setter Property="TextMargin" Value="5" />
        <Setter Property="ContentWidth" Value="Auto" />
        <Setter Property="ContentHeight" Value="{DynamicResource ColoredContentAndTextButtonContentHeight}" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ContentAndTextButton}">
                    <Grid x:Name="contentContainer" Background="Transparent">
                        <DockPanel Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">

                            <!-- Content (= Image) -->
                            <Grid x:Name="grid" Margin="10" Background="#02FFFFFF" DockPanel.Dock="Left"
                              Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}">
                                    <Grid>
                                        <!-- Content, e.g. Icon -->
                                        <Rectangle x:Name="rectangle"  Width="{DynamicResource ColoredContentAndTextButtonIconWidth}" Height="{DynamicResource ColoredContentAndTextButtonIconHeight}" Fill="{TemplateBinding Background}">
                                            <Rectangle.OpacityMask>
                                                <VisualBrush>
                                                    <VisualBrush.Visual>
                                                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                    </VisualBrush.Visual>
                                                </VisualBrush>
                                            </Rectangle.OpacityMask>
                                        </Rectangle>

                                    </Grid>
                                </Viewbox>
                            </Grid>

                            <!-- Text -->
                            <TextBlock x:Name="PART_TextBlock" Text="{TemplateBinding Text}" Foreground="{TemplateBinding Foreground}"
                                   Margin="{TemplateBinding TextMargin}" TextWrapping="WrapWithOverflow"
                                   Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                                   HorizontalAlignment="Left" VerticalAlignment="Center" />

                        </DockPanel>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="TextDock" Value="Right">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Left">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Top">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Bottom">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top" />
                        </Trigger>
                        <Trigger Property="IsFocused" Value="True">
                          <Setter Property="Background" TargetName="contentContainer" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BrushToTransmittantBrushConverter}, ConverterParameter=0.12}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <!--<Setter TargetName="ellipsebg" Property="Opacity" Value="0.2" />-->
                            <!--<Setter TargetName="PART_TextBlock" Property="Opacity" Value="0.6" />-->
                            <Setter TargetName="contentContainer" Property="Background" Value="{DynamicResource ColoredContentAndTextButtonMouseOverBrush}" />

                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="contentContainer" Property="RenderTransformOrigin" Value="0.5, 0.5" />
                            <Setter TargetName="contentContainer" Property="RenderTransform">
                                <Setter.Value>
                                    <ScaleTransform ScaleX="0.95" ScaleY="0.95" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="0.5" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
